package com.stackandqueue;

import java.util.Stack;

public class ImplementQueueUsingStacks0203_232 {

}

class MyQueue {
    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        if(!stackOut.empty()) return stackOut.pop();
        while (!stackIn.empty()){
            stackOut.push(stackIn.pop());
        }
        return stackOut.pop();
    }

    public int peek() {
        if(!stackOut.empty()) return stackOut.peek();
        while (!stackIn.empty()){
            stackOut.push(stackIn.pop());
        }
        return stackOut.peek();
    }

    public boolean empty() {
        return stackOut.empty() && stackIn.empty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int p
 */
